﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace System
{
	/// <summary>
	/// Defines Extension-Methods for classes in the <see cref="System.WindowsForms"/> namespace.
	/// </summary>
	public static class ArgusLibExtensions
	{
		public static Point PointToClient(this Control client, Control control, Point point)
		{
			point = control.PointToScreen(point);
			point = client.PointToClient(point);
			return point;
		}
	}
}

namespace ArgusLib.Controls
{
	public static class ArgusLibExtensions
	{
		public static bool Check(this IEnumerable<CharSet> allowedChars, char c)
		{
			bool RetVal = true;
			if (allowedChars != null)
			{
				RetVal = false;
				foreach (CharSet set in allowedChars)
				{
					if (set.Check(c) == true)
					{
						RetVal = true;
						break;
					}
				}
			}
			return RetVal;
		}

		public static string RemoveUnallowedChars(this IEnumerable<CharSet> allowedChars, string input)
		{
			if (allowedChars == null)
				return input;
			List<char> chars = new List<char>(input.Length);
			for (int i = 0; i < input.Length; i++)
			{
				if (allowedChars.Check(input[i]) == true)
					chars.Add(input[i]);
			}
			return new string(chars.ToArray());
		}

		public static bool ContainsUnallowedChars(this IEnumerable<CharSet> allowedChars, string input)
		{
			if (allowedChars == null)
				return false;
			for (int i = 0; i < input.Length; i++)
			{
				if (allowedChars.Check(input[i]) == false)
					return true;
			}
			return false;
		}
	}
}
